package demoMod.invincibleOne.cards.invincible;

import basemod.helpers.CardModifierManager;
import com.megacrit.cardcrawl.actions.AbstractGameAction;
import com.megacrit.cardcrawl.cards.AbstractCard;
import com.megacrit.cardcrawl.characters.AbstractPlayer;
import com.megacrit.cardcrawl.core.CardCrawlGame;
import com.megacrit.cardcrawl.dungeons.AbstractDungeon;
import com.megacrit.cardcrawl.localization.CardStrings;
import com.megacrit.cardcrawl.monsters.AbstractMonster;
import demoMod.invincibleOne.InvincibleOneMod;
import demoMod.invincibleOne.enums.CardTagsEnum;
import demoMod.invincibleOne.modifiers.ExhaustAtStartOfCombatMod;
import demoMod.invincibleOne.relics.TaskGoal;

public class LeechSeed extends AbstractInvincibleCard {
    public static final String ID = InvincibleOneMod.makeID("LeechSeed");

    private static final CardStrings cardStrings = CardCrawlGame.languagePack.getCardStrings(ID);
    public static final String NAME = cardStrings.NAME;
    public static final String DESCRIPTION = cardStrings.DESCRIPTION;
    public static final String IMG_PATH = "cards/LeechSeed.png";

    private static final CardType TYPE = CardType.SKILL;
    private static final CardRarity RARITY = CardRarity.UNCOMMON;
    private static final CardTarget TARGET = CardTarget.NONE;

    private static final int COST = -2;

    public LeechSeed() {
        super(ID, NAME, InvincibleOneMod.getResourcePath(IMG_PATH), COST, DESCRIPTION, TYPE, RARITY, TARGET);
        this.baseMagicNumber = this.magicNumber = 2;
        this.tags.add(CardTagsEnum.VIRUS);
        this.modifier = new ExhaustAtStartOfCombatMod();
        CardModifierManager.addModifier(this, modifier);
        this.rawDescription = String.format(DESCRIPTION, this.misc);
        this.initializeDescription();
        this.isEthereal = true;
        this.tags.add(CardTags.HEALING);
    }

    @Override
    public boolean onBattleStart() {
        if (misc > 0 && AbstractDungeon.player.masterDeck.contains(this)) {
            TaskGoal.AddToAlertQueue(32, new TaskGoal.AlertLambda() {
                @Override
                public void run() {
                    for (AbstractMonster m : AbstractDungeon.getMonsters().monsters) {
                        addToTop(new AbstractGameAction() {
                            @Override
                            public void update() {
                                m.increaseMaxHp(misc, true);
                                isDone = true;
                            }
                        });
                    }
                }
            });
        }
        return false;
    }

    @Override
    public Runnable getUpgradeAction() {
        return () -> {
            this.rawDescription = String.format(cardStrings.UPGRADE_DESCRIPTION, this.misc);
            this.initializeDescription();
            this.isEthereal = false;
        };
    }

    @Override
    public void use(AbstractPlayer p, AbstractMonster m) {
        this.misc += this.magicNumber;
        this.rawDescription = String.format(DESCRIPTION, this.misc);
        this.initializeDescription();
        for (AbstractCard card : p.masterDeck.group) {
            if (card.uuid.equals(uuid)) {
                card.misc = this.misc;
                card.rawDescription = String.format(DESCRIPTION, this.misc);
                card.initializeDescription();
                break;
            }
        }
    }
}
